package com.jic.product.controller.store;
import com.jic.product.constant.consist.ResponseCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import com.github.pagehelper.PageInfo;
import java.util.List;
import java.util.stream.Collectors;
import com.jic.common.base.vo.RestResult;
import lombok.extern.slf4j.Slf4j;
import com.alibaba.fastjson.JSONObject;
import com.jic.product.model.vo.request.MStoreDictsRequest;
import com.jic.product.model.vo.response.MStoreDictsResponse;
import com.jic.product.model.entity.MStoreDicts;
import com.jic.product.service.MStoreDictsService;
/**
 * @Author: 建投数据科技(山东)有限公司 
 * @date: 2020-04-29 11:56:56
 */
 @RestController
 @Slf4j
 @RequestMapping("/mStoreDicts")
 @Api(tags = " [库存操作字典表]控制类-PC")
public class MStoreDictsController {
	@Autowired
	private MStoreDictsService service;
	
	/**
	 * 新增记录
	 * @param request 新增[库存操作字典表]请求参数
	 * @return MStoreDictsResponse 新增[库存操作字典表]响应参数
	 * author 建投数据科技(山东)有限公司
	 * @date 2020-3-11 20:54:04
	 */
	@ApiOperation(value = "新增[库存操作字典表]记录")
	@PostMapping("/save")
	@ResponseBody
	public RestResult<Long> save(@RequestBody MStoreDictsRequest request) throws Throwable {
			MStoreDicts mStoreDicts = new MStoreDicts();
			BeanUtils.copyProperties(request, mStoreDicts);
		long flag = service.save(mStoreDicts);
	 return RestResult.success(flag);
	}
	/**
	 * 新增或修改记录
	 * @param request 新增或修改[库存操作字典表]请求参数
	 * @return MStoreDictsResponse 新增或修改[库存操作字典表]响应参数
	 * author 建投数据科技(山东)有限公司
	 * @date 2020-3-11 20:54:04
	 */
	@ApiOperation(value = "保存或更新[库存操作字典表]")
	@PostMapping("/saveOrUpdate")
	@ResponseBody
	public RestResult<Long> saveOrUpdate(@Validated @RequestBody MStoreDictsRequest request) throws Throwable {
			MStoreDicts mStoreDicts = new MStoreDicts();
			BeanUtils.copyProperties(request, mStoreDicts);
		long flag =   service.saveOrUpdate(mStoreDicts);
	 return RestResult.success(flag);
	}
	/**
	 * 删除记录
	 * @param request 删除[库存操作字典表]请求参数
	 * @return MStoreDictsResponse 删除[库存操作字典表]响应参数
	 * author 建投数据科技(山东)有限公司
	 * @date 2020-3-11 20:54:04
	 */
	@ApiOperation(value = "删除[库存操作字典表]记录")
	@PostMapping("/delete")
	@ResponseBody
	public RestResult<Long> delete(@RequestBody MStoreDictsRequest request) throws Throwable {
			MStoreDicts mStoreDicts = new MStoreDicts();
			BeanUtils.copyProperties(request, mStoreDicts);
		long flag = service.deleteByPrimaryKeyLogically(mStoreDicts);
	 return RestResult.success(flag);
	}
	/**
	 * 修改记录
	 * @param request 修改[库存操作字典表]请求参数
	 * @return MStoreDictsResponse 修改[库存操作字典表]响应参数
	 * author 建投数据科技(山东)有限公司
	 * @date 2020-3-11 20:54:04
	 */
	@ApiOperation(value = "修改[库存操作字典表]记录")
	@PostMapping("/update")
	@ResponseBody
	public RestResult<Long> update(@RequestBody MStoreDictsRequest request) throws Throwable {
		MStoreDicts mStoreDicts = new MStoreDicts();
		BeanUtils.copyProperties(request, mStoreDicts);
		long flag = service.updateByPrimaryKeySelective(mStoreDicts);
	 	return RestResult.success(flag);
	}
	/**
	 * 单表查询详情信息
	 * @param request 查询[库存操作字典表]详情请求参数
	 * @return MStoreDictsResponse 查询[库存操作字典表]详情响应参数
	 * author 建投数据科技(山东)有限公司
	 * @date 2020-3-11 20:54:04
	 */
	 @PostMapping("/getByPrimaryKey")
	 @ApiOperation(value = "查询[库存操作字典表]详情")
	 @ResponseBody
	public RestResult<MStoreDictsResponse> getByPrimaryKey(@Validated  @RequestBody MStoreDictsRequest request) {
		log.info("查询详情请求参数入参，{}", JSONObject.toJSONString(request));
		if (request!=null && request.getId()!=null) {

			MStoreDicts mStoreDicts = new MStoreDicts();
			BeanUtils.copyProperties(request, mStoreDicts);
			MStoreDicts result = service.getByPrimaryKey(mStoreDicts);
			log.info("查询详情请求参数出参，{}", JSONObject.toJSONString(result));
			if (result == null) {
				return RestResult.error(ResponseCode.EXCEPTION, "记录不存在");
			}
			MStoreDictsResponse bo = new MStoreDictsResponse();
			BeanUtils.copyProperties(result, bo);
			return RestResult.success(bo);
		}
		log.info("查询详情请求结束");
		return RestResult.success(null);
	}
	 /**
		 * 分页查询
		*
		* @param request 分页查询请求参数
		* @return 分页列表
		  * @throws Throwable 业务异常和系统异常
		 */
	@PostMapping("/listPage")
	@ApiOperation(value = " 分页查询列表 ")
	@ResponseBody
	public RestResult<PageInfo<MStoreDicts>> listPage (@RequestBody MStoreDictsRequest request) throws Throwable {
	 MStoreDicts param = new MStoreDicts();
	 BeanUtils.copyProperties(request, param);
		return RestResult.success(service.listPageBySelective(param, request.getPageNum(), request.getPageSize()));
	}

/**
	 * M_STORE_DICTS 查询列表（不分页）
	 * @param  request 前端请求参数
 */
 @PostMapping("/listAll")
 @ApiOperation(value = "不分页查询子类 [库存操作字典表] ")
 @ResponseBody
 public RestResult<List<MStoreDictsResponse>>  listMStoreDictsAllRecord(@RequestBody MStoreDictsRequest request) throws Throwable {
 		MStoreDicts mStoreDicts = new MStoreDicts();
		BeanUtils.copyProperties(request, mStoreDicts);

		List<MStoreDicts> list = service.listAllRecord(mStoreDicts);
			List<MStoreDictsResponse> responseList = list.stream().map(temp -> {
			MStoreDictsResponse bo = new MStoreDictsResponse();
			BeanUtils.copyProperties(temp, bo);
			return bo;
			}).filter(item -> item != null).collect(Collectors.toList());
		return RestResult.success(responseList);
}

	@PostMapping(value = "/queryDictsOperateList")
	public RestResult<List<MStoreDicts>> queryDictsOperateList(@RequestBody MStoreDictsRequest request) {
		MStoreDicts mStoreDicts = new MStoreDicts();
		BeanUtils.copyProperties(request, mStoreDicts);
		List<MStoreDicts> mStoreDictsList = service.query(mStoreDicts);
		return RestResult.success(mStoreDictsList);
	}

}

